package com.mondo.financialwallet.presentation.model;

import android.graphics.Color;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.StringRes;

import com.mondo.financialwallet.R;
import com.mondo.financialwallet.presentation.utils.DateUtils;

import java.io.Serializable;

public class TokenTransactionRecord implements Serializable {

    public static final int TRANSFER = 1, TRANSFER_OUT = 2;

    private String name;

    // 转入或转出 1转入  2 转出
    private int direction;

    // 时间
    private String time;

    // 数量
    private String amount;

    // 地址
    private String fromAddress;

    // 地址
    private String toAddress;

    // 区块高度
    private int blockHeight;

    // 备注
    private String remark;

    // 交易号
    private String transactionNumber;

    // 手续费
    private double gas;

    // 状态
    private int status;

    public TokenTransactionRecord(
            String name, int direction, long time, String amount, String fromAddress, String toAddress,
            int blockHeight, String remark, String transactionNumber, int status, double gas) {
        this.direction = direction;
        this.time = DateUtils.timestampToTime((int) time);
        this.amount = amount;
        this.fromAddress = fromAddress;
        this.toAddress = toAddress;
        this.blockHeight = blockHeight;
        this.remark = remark;
        this.transactionNumber = transactionNumber;
        this.status = status;
        this.name = name;
        this.gas = gas;
    }

    public String getName() {
        return name;
    }

    public int getDirection() {
        return direction;
    }

    public String getTime() {
        return time;
    }

    public String getAmount() {
        if (direction == 1){
            return "+" + amount;
        } else {
            return "-" + amount;
        }
    }

    public @ColorInt int getAmountColor(){
        if (direction == 1){
            return Color.parseColor("#3F82DD");
        } else {
            return Color.parseColor("#FF9600");
        }
    }

    public String getFromAddress() {
        return fromAddress;
    }

    public String getToAddress() {
        return toAddress;
    }

    public int getBlockHeight() {
        return blockHeight;
    }

    public String getRemark() {
        return remark;
    }

    public String getTransactionNumber() {
        return transactionNumber;
    }

    public int getStatus() {
        return status;
    }

    public @StringRes int getStatusText() {
        switch (status){
            case 1:
                return R.string.text_status_under_review;
            case 2:
                return R.string.text_status_packed;
            default:
                return R.string.text_status_success;
        }
    }

    public @ColorRes
    int getStatusColor() {
        switch (status){
            case 1: return R.color.colorPrimaryText;
            case 2: return R.color.colorFailure;
            default: return R.color.colorSuccess;
        }
    }

    public double getGas() {
        return gas;
    }
}
